<?php
/**
 * jishupu-cms
 * @Author:技术铺<jishupu@qq.com>
 * @Date: 2021/11/11
 */
namespace App\Http\Requests;

/**
 * 表单请求验证演示类
 * Class DemoRequest
 * @package App\Http\Requests
 */
class DemoRequest extends BaseRequest
{
    /**
     * 用户是否有权操作，true是，false否
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 字段验证规则
     *
     * @return array
     */
    public function rules()
    {
//        $demo = Demo::find($this->input('id'));
        return [
            'id' => 'required',
            'title' => 'required|max:10',
/* 唯一性规则案例 'title' => ['required', 'min:2', 'max:30', Rule::unique('demo')->ignore($demo)->where(function ($query) {
                $query->where('deleted_at', null);
            })],*/
            'content' => 'required|max:255',
        ];
    }

    /**
     * 提示信息
     *
     * @return array
     */
    public function messages()
    {
        return [
        ];
    }

    /**
     * 定义场景
     *
     * @var \string[][]
     */
    public $scenes = [
        'store' => ['title', 'content'],
        'update' => ['id', 'title', 'content'],
        'destroy' => ['id'],
    ];

    /**
     * 验证错误的自定义属性
     *
     * @return array
     */
    public function attributes()
    {
        return [
            'id' => 'ID',
            'title' => '标题',
            'content' => '内容'
        ];
    }

    /**
     * 验证前
     *
     * @return void
     */
    protected function prepareForValidation()
    {
    }

}
